package cn.kgc.ssm.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author 课工场
 * @date 2024/11/14
 * @description    统一响应结果
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult {

    private Integer code;
    private String msg;
    private Long count;
    private Object data;

    private ResponseResult(){ }

    // 业务成功
    public static  ResponseResult   success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.SUCCESS.getCode());
        responseResult.setMsg(ResponseStatus.SUCCESS.getMessage());
        return  responseResult;
    }

    // 业务失败
    public static  ResponseResult   fail(){

        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.FAIL.getCode());
        responseResult.setMsg(ResponseStatus.FAIL.getMessage());

        return  responseResult;
    }

    // 程序异常
    public static  ResponseResult   error(){

        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(ResponseStatus.ERROR.getCode());
        responseResult.setMsg(ResponseStatus.ERROR.getMessage());

        return  responseResult;
    }


     public ResponseResult  data(Object data){
         this.data = data;
         return this;
     }

    public ResponseResult  count(Long count){
        this.count = count;
        return this;
    }


    public ResponseResult  code(ResponseStatus responseStatus){
        this.code= responseStatus.getCode();
        return this;
    }


    public ResponseResult  msg(String message){
        this.msg = message;
        return this;
    }


}
